package com.dao;

import com.pojo.Student;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * Created By ShaoXikai on 2022/7/14
 */
public interface StudentDao {

    @Select("select s.s_name, s.s_sex, s.s_age, s.cid from tedu.student s,tedu.clazz c")
    List<Student> findAll();

    @Select("select * from tedu.student")
    @Results(id = "oneToOneMapping", value = {
            @Result(id = true, column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "s_name", property = "sName"),
            @Result(column = "s_sex", property = "sSex"),
            @Result(column = "s_age", property = "sAge"),
            @Result(column = "cid", property = "cid"),
            @Result(column = "cid", property = "clazz",
                    one = @One(select = "com.dao.ClazzDao.findClazzByCid",
                            fetchType = FetchType.LAZY))
    })
    List<Student> queryAllStuInfo();

    @Select("select  * from tedu.student where cid = #{cid}")
    @Results(id = "ddd", value = {
            @Result(id = true, column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "s_name", property = "sName"),
            @Result(column = "s_sex", property = "sSex"),
            @Result(column = "s_age", property = "sAge"),
            @Result(column = "cid", property = "cid"),
    })
    List<Student> findByCid(Integer cid);

    @Select("select * from tedu.student where id = #{id}")
    @ResultMap("ddd")
    Student findStuById(Integer id);

}
